<?php
$arr = [2, 1, 5, 12, 65, 32, 29, 122, 113];
function sortArr(array $arr)
{
    for ($i = 0; $i < count( $arr ); $i++) {
        for ($j = 0; $j < count( $arr ) - $i - 1; $j++) {
            if ($arr[$j] > $arr[$j + 1]) {
                $temp = $arr[$j];
                $arr[$j] = $arr[$j + 1];
                $arr[$j + 1] = $temp;
            }
        }
    }
    return $arr;
}

function divideFind(int $target, array $arr)
{
    $left = 0;
    $right = count( $arr );
    while ($left <= $right) {
        $med = ($left + $right) / 2;
        if ($target === $arr[$med]) {
            echo '找到了';
            return true;
        } elseif ($target < $arr[$med]) {
            $right = $med;
        } elseif ($target > $arr[$med]) {
            $left = $med + 1;
        }
    }
    echo '没有';
    return false;
}

divideFind( 15, sortArr( $arr ) );
